package com.wanfajie.smsdistribute.template.convert.impl

import android.text.Spannable
import android.text.SpannableString
import android.text.Spanned
import android.text.style.CharacterStyle
import com.wanfajie.smsdistribute.template.convert.TemplateConverter

class TemplateSpannableConverter(private val spanFactory: () -> CharacterStyle)
    : TemplateConverter<Spannable> {

    private lateinit var spanStr: Spannable

    override fun setRawMaterial(s: CharSequence) {
        spanStr = SpannableString(s)
    }

    override fun mark(name: CharSequence, e: Pair<Int, Int>) {
        val span = spanFactory.invoke()
        spanStr.setSpan(span, e.first, e.second, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
    }

    override fun convert(): Spannable = spanStr
}
